﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class ImageUpload : FileUpload
    {
        public ImageUpload()
        {
            this.FileExtensions = SiteSettings.Settings.ImageExtensions;
        }

        public override string SaveAs(string fileName)
        {
            string fileUrl = base.SaveAs(fileName);
            if (string.IsNullOrEmpty(fileUrl))
                return fileUrl;

            if (IsThumbnail)
                ImageHelper.CreateThumbnail(fileUrl);
            if (IsWaterMark)
                ImageHelper.MakeWatermark(WaterMarkText, string.Empty, fileUrl);
            return fileUrl;
        }

        /// <summary>
        /// 是否打水印，默认false
        /// </summary>
        public bool IsWaterMark { get; set; }

        private string waterMarket = string.Empty;
        public string WaterMarkText
        {
            get { return string.IsNullOrEmpty(waterMarket) ? SiteSettings.Settings.SiteDomain : waterMarket; }
            set { waterMarket = value; }
        }

        /// <summary>
        /// 是否生成缩略图，默认false
        /// </summary>
        public bool IsThumbnail { get; set; }

        public override string FileExtensions
        {
            get { return base.FileExtensions; }
            set { base.FileExtensions = value; }
        }
    }
}
